<template>
  <div id="inviteWithdrawal">
    <h1 class="con-right-title">转介绍提现记录</h1>
    <topSearch
      :form-inline="formInline"
      :activityAll="activityAll"
      @toSearch="toSearch"
      ref="topSearch"
    ></topSearch>
    <!-- 表格部分 -->
    <el-table :data="tableData" stripe ref="table">
      <el-table-column type="index" label="序号" width="50" align="center">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人" align="center">
        <template v-slot="{ row }">
          {{ row.userName }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人大鹏号" align="center">
        <template v-slot="{ row }">
          {{ row.dpAccount }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人手机号" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.phone }}
        </template>
      </el-table-column>
      <el-table-column label="最新提现时间" min-width="150" align="center">
        <template v-slot="{ row }">
          <div class="activity-time__wrap">
            <span>{{ row.newWithdrawTime }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="提现总金额" min-width="100" align="center">
        <template v-slot="{ row }"> {{ row.sumWithdrawMoney }}元 </template>
      </el-table-column>
      <el-table-column label="活动状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.activityStatus == 'NOT_STARTED'">未开始</span>
          <span v-if="row.activityStatus == 'ONGOING'">进行中</span>
          <span v-if="row.activityStatus == 'OVER'">已结束</span>
        </template>
      </el-table-column>
      <el-table-column label="活动名称" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.activityName }}
        </template>
      </el-table-column>
      <el-table-column label="提现状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.giveOffStatus == 'YES'">已发放</span>
          <span v-if="row.giveOffStatus == 'NO'">未发放</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template v-slot="{ row }">
          <div class="action-wrap">
            <el-button
              v-if="row.giveOffStatus == 'NO'"
              type="text"
              @click="dialogFormVisibleShow(row)"
              >提现</el-button
            >
            <el-button v-else type="text" @click="dialogTableVisibleShow(row)"
              >提现明细</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pageCom
      :searchParams="searchParams"
      @searchList="searchList"
      :total="total"
    ></pageCom>
    <!--  提现 弹窗 -->
    <withdrawDialog
      v-if="dialogFormVisible"
      :showDialog.sync="dialogFormVisible"
      :withdrawAllMoney="withdrawAllMoney"
      :activityAll="activityAll"
      :id="id"
    />
    <!-- 提现明细弹窗 -->
    <chooseBounced :show.sync="dialogTableVisible" :gridData="gridData" />
  </div>
</template>

<script>
import topSearch from './topSearch'
import chooseBounced from './chooseBounced'
import withdrawDialog from './withdrawDialog'
import {
  getwithdrawList,
  getAllActivity,
  getwithdrawDetail
} from '@/api/withdrawList/index'
export default {
  name: 'inviteWithdrawal',
  components: {
    topSearch,
    chooseBounced,
    withdrawDialog
  },
  data() {
    return {
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      // 总条数
      total: 0,
      // 查看 提现弹窗
      dialogFormVisible: false,
      // 提现明细弹窗
      dialogTableVisible: false,
      // 搜索条件
      formInline: {
        time: [],
        activityId: '', //活动id
        dpAccount: '', // 大鹏号 or 手机号
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        status: '' // 状态
      },
      // 表格数据
      tableData: [],
      // 全部活动
      activityAll: [],
      // 提现传的id
      id: '',
      // 明细列表
      gridData: [],
      // 提现总金额
      withdrawAllMoney: 0
    }
  },
  created() {
    // 获取 全部活动 的 id
    this.getAllActivity()
    // 获取列表
    this.searchList()
  },
  methods: {
    /* 获取列表 */
    searchList() {
      let params = { ...this.searchParams, ...this.formInline }
      getwithdrawList(
        params,
        (res) => {
          if (res.rows) {
            this.tableData = res.rows
            this.total = res.total
          }
        },
        (err) => {
          console.log(err)
        }
      )
    },
    // 获取全部活动
    getAllActivity() {
      let params = ''
      getAllActivity(
        params,
        (res) => {
          this.activityAll = res
        },
        (err) => {
          console.log(err)
        }
      )
    },

    // 点击提现
    dialogFormVisibleShow(row) {
      // 提现总金额
      this.withdrawAllMoney = row.sumWithdrawMoney
      this.dialogFormVisible = true
      this.id = row.id
    },
    // 点击提现明细
    dialogTableVisibleShow(row) {
      // 获取 邀请记录提现表
      let params = { activityId: row.activityId, userId: row.userId }
      getwithdrawDetail(
        params,
        (res) => {
          this.gridData = res.rows
        },
        (err) => {
          console.log(err)
        }
      )
      // 提现明细弹窗
      this.dialogTableVisible = true
    },
    // 查询按钮
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    refreshList() {
      this.searchParams.pageNum = 1
      this.searchList()
    }
  }
}
</script>

<style lang="less" scoped>
#inviteWithdrawal {
  .dialog-footer .el-button {
    flex: 1;
  }
  :deep(.el-dialog__header) {
    border-bottom: 0 !important;
  }
  :deep(.el-select) {
    width: 190px !important;
  }
  :deep(.widen .el-form-item__content) {
    width: 256px !important;
  }
}
</style>
